package com.jspxcms.plug.repository;

import com.jspxcms.plug.domain.UserExchange;
import com.jspxcms.plug.domain.UserFavorite;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;

import java.util.List;

/**
 * Created by yuanyue on 14-9-21.
 */
public interface UserFavoriteDao extends Repository<UserFavorite, Integer>, UserFavoriteDaoPlus {

    public UserFavorite save(UserFavorite favorite);

    public List<UserFavorite> findByUserIdAndNewsId(Integer userId, Integer id);

    public Page<UserFavorite> findAll(Specification<UserFavorite> spec, Pageable page);

    @Modifying
    @Query("delete from UserFavorite bean where bean.userId =?1 and bean.newsId =?2")
    int delete(Integer userId, Integer id);
}
